package com.zz.admin.subTableManagement.controller;

import com.zz.admin.subTableManagement.dto.SubTableDto;
import com.zz.admin.subTableManagement.service.SubTableService;
import java.util.List;
import java.util.Map;

import com.zz.common.base.dto.PageListResultDto;
import com.zz.common.base.dto.ResponseDTO;
import com.zz.common.base.dto.ResultDto;
import com.zz.common.constants.ApiConstants;

import io.swagger.annotations.Api;
import jakarta.annotation.Resource;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 子 服务接口类
 * @author zl
 * @since 2025-11-18 19:00:16
 */
@Api(tags = "子服务接口类")
@RestController
@RequestMapping("sub-table-management/v1.0/sub-table")
public class SubTableController {

    @Resource
    private SubTableService subTableService;

    @RequestMapping(value = "/query-with-page", method = RequestMethod.POST)
    @ApiOperation(value = "子-分页查询", notes = "传入分页信息")
    public PageListResultDto<SubTableDto> queryWithPage(@RequestBody SubTableDto subTableDto) {
        PageListResultDto<SubTableDto> res;
        res = subTableService.queryWithPage(subTableDto, subTableDto.getQueryParam());
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    
    @RequestMapping(value = "/query-with-no-page", method = RequestMethod.POST)
    @ApiOperation(value = "子-不分页查询", notes = "传入查询条件信息")
    public ResponseDTO<List<SubTableDto>> queryWithNoPage(@RequestBody SubTableDto subTableDto) {
        ResponseDTO<List<SubTableDto>> res = new ResponseDTO<>();
        res.setData(subTableService.queryWithNoPage(subTableDto));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "子-查询ById", notes = "传入id")
    public ResponseDTO<SubTableDto> queryById(@PathVariable("id") String id) {
        ResponseDTO<SubTableDto> res = new ResponseDTO<>();
        SubTableDto result = subTableService.queryById(id);
        res.setData(result);
        return res;
    }

    @RequestMapping(value = "/query-by-ids", method = RequestMethod.POST)
    @ApiOperation(value = "子-查询ByIds", notes = "传入ids")
    public ResponseDTO<List<SubTableDto>> queryByIds(@RequestBody List<String> ids) {
        ResponseDTO<List<SubTableDto>> res = new ResponseDTO<>();
        res.setData(subTableService.queryByIds(ids));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/query-by-parent-id/{parentId}", method = RequestMethod.GET)
    @ApiOperation(value = "子-通过外键查询", notes = "传入parentId")
    public ResponseDTO<List<SubTableDto>> queryByParentId(@PathVariable("parentId") String parentId) {
        ResponseDTO<List<SubTableDto>> res = new ResponseDTO<>();
        res.setData(subTableService.queryByParentId(parentId));
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "子-创建", notes = "创建")
    public ResultDto save(@RequestBody SubTableDto subTableDto) {
        ResultDto res = new ResultDto();
        subTableService.save(subTableDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/save-batch", method = RequestMethod.POST)
    @ApiOperation(value = "子-创建", notes = "创建")
    public ResultDto saveBatch(@RequestBody List<SubTableDto> subTableDtos) {
        ResultDto res = new ResultDto();
        subTableService.saveBatch(subTableDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    @ApiOperation(value = "子-修改", notes = "修改")
    public ResultDto modify(@RequestBody SubTableDto subTableDto) {
        ResultDto res = new ResultDto();
        subTableService.modify(subTableDto);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/modify-batch", method = RequestMethod.POST)
    @ApiOperation(value = "子-修改", notes = "修改")
    public ResultDto modifyBatch(@RequestBody List<SubTableDto> subTableDtos) {
        ResultDto res = new ResultDto();
        subTableService.modifyBatch(subTableDtos);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "子-删除ById", notes = "传入id")
    public ResultDto delete(@PathVariable("id")  String id) {
        ResultDto res = new ResultDto();
        subTableService.delete(id);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete-batch", method = RequestMethod.POST)
    @ApiOperation(value = "子-批量删除", notes = "传入id")
    public ResultDto deleteBatch(@RequestBody List<String> ids) {
        ResultDto res = new ResultDto();
        subTableService.deleteBatch(ids);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete-by-parent-id/{parentId}", method = RequestMethod.GET)
    @ApiOperation(value = "子-通过外键删除", notes = "传入parentId")
    public ResultDto deleteByParentId(@PathVariable("parentId") String parentId) {
        ResultDto res = new ResultDto();
        subTableService.deleteByParentId(parentId);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

    @RequestMapping(value = "/delete-by-parent-ids", method = RequestMethod.POST)
    @ApiOperation(value = "子-通过外键批量删除", notes = "传入parentIds")
    public ResultDto deleteByParentIds(@RequestBody List<String> parentIds) {
        ResultDto res = new ResultDto();
        subTableService.deleteByParentIds(parentIds);
        res.setCode(ApiConstants.RESULT_SUCCESS);
        res.setMessage(ApiConstants.MESSAGE_SUCCESS);
        return res;
    }

}